import { createApp } from 'vue'
import './style.css'
import App from './App.vue'
import LifeService from './lifeservice/index.js'

// 创建Vue应用实例
const app = createApp(App)

// 配置LifeService框架
const lifeServiceConfig = {
  autoBoot: true,
  errorHandler: (error) => {
    console.error('LifeService Error:', error)
  },
  globalConfig: {
    appName: 'My Vue App',
    environment: import.meta.env.MODE || 'development'
  }
}

// 安装LifeService框架
app.use(LifeService, lifeServiceConfig)

// 创建一些示例服务用于演示
const { lifedervice } = LifeService

// 注册示例日志服务
lifedervice.register('logger', {
  info(message) {
    console.log(`[INFO] ${message}`)
  },
  error(message) {
    console.error(`[ERROR] ${message}`)
  },
  boot(options) {
    console.log('Logger service booted with options:', options)
  }
}, { priority: 10 })

// 注册示例API服务
lifedervice.register('api', class ApiService {
  constructor(container) {
    this.container = container
    this.baseUrl = '/api'
  }
  
  boot(options) {
    const logger = this.container.get('logger')
    logger.info('API service booted')
    this.baseUrl = options.baseUrl || this.baseUrl
  }
  
  async get(endpoint) {
    const logger = this.container.get('logger')
    logger.info(`Making GET request to ${this.baseUrl}${endpoint}`)
    // 实际项目中这里会发起真实的API请求
    return { success: true, data: {}, message: 'Mock API response' }
  }
}, { 
  priority: 5,
  dependencies: ['logger'],
  config: { baseUrl: '/api/v1' }
})

// 挂载应用
app.mount('#app')
